package cn.itlaobing.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itlaobing.entity.Account;
import cn.itlaobing.entity.Student;
import cn.itlaobing.repository.AccountJpaRepository;
import cn.itlaobing.repository.JpaRepository;
import cn.itlaobing.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {

	@Autowired
	private AccountJpaRepository accountJpaRepository;
	
	@Autowired
	private JpaRepository studentJpaRepository;
	
	
	
	@Transactional
	@Override
	public void allocatAccount(Student student, Account account) {
		account.setStudent(student);
		accountJpaRepository.save(account);
		
		student.setAccount(account);
		studentJpaRepository.save(student);

	}

	@Override
	public void save(Student student) {
		studentJpaRepository.save(student);

	}

	@Override
	public Student findById(Long id) {
		
		return studentJpaRepository.findOne(id);
	}

}
